
package com.netease.xone.itemview;

import protocol.meta.UserAdvice;
import Utils.TimeFormatUtil;
import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;
import android.widget.TextView.BufferType;

import com.netease.xone.R;
import com.netease.xone.widget.LoadingImageView;

public class RenderAdviceView {

    private TextView adviceInfo;// 签名
    private TextView adviceTime;
    private LoadingImageView userAvatarImage;

    public RenderAdviceView(View v) {
        adviceInfo = (TextView)v.findViewById(R.id.advice_info);
        adviceTime = (TextView)v.findViewById(R.id.advice_time);
        userAvatarImage = (LoadingImageView)v.findViewById(R.id.advice_user_avatar);
        int avatarDimension = v.getResources().getDimensionPixelSize(R.dimen.common_avatar_size);
        userAvatarImage.setServerClipSize(avatarDimension, avatarDimension);
    }

    public void renderView(final Context context, final UserAdvice advice) {
        if(advice == null)return;
        userAvatarImage.setImageResource(R.drawable.avatar_user_default_50);
        if(advice.user != null && advice.user.avatar != null){
            userAvatarImage.setLoadingImage(advice.user.avatar);
        }
        String userName = advice.user == null ? "" : advice.user.nickname;
        String adviceContent = userName + advice.content;
        adviceInfo.setText(adviceContent, BufferType.SPANNABLE);
        Spannable span = (Spannable)adviceInfo.getText();
        int start = 0;
        int end = userName.length();
        span.setSpan(new ForegroundColorSpan(Color.WHITE), start, end,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        adviceTime.setText(TimeFormatUtil.getTimeFormat(context, advice.createTime));
    }
}
